<?php
	/**
	 * 测试充值局数卡
	 */
    class DepositCard extends APIBase {
		
		public $tag = "DepositCard";
    	public $isLogin = false;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}
		public function logic() {
			if(!isset($this->param['skey'])){
				echo '301充值失败';exit;
			}
			if(!isset($this->param['accid'])){
				echo '302充值失败';exit;
			}
			if(!isset($this->param['num'])){
				echo '303充值失败';exit;
			}
			$skey = $this->param['skey'];
            $accid = $this->param['accid'];
			$count = $this->param['num'];
			
			if($skey!='abcdefg123456'){
				echo '不能乱充,diu';exit;
			}
			
			if($count>1000){
				echo '不能充超1000的数量,diu';exit;
			}
			
			$result = $this->mysql->find('select id from player where accid='.$accid);

			if(empty($result)){
				echo 'accid不存在,diu';
			}
			
			$uid = $result[0]['id'];
			$is_exists = $this->cache_redis->exists('hbackpack:'.$uid.':1');
			if($is_exists){
				$this->cache_redis->hset('hbackpack:'.$uid.':1','count',$count);
				echo '充值成功!!';
			}else{
				$ret = $this->mysql->update('backpack',array('count'=>$count),array('uid'=>$uid,'propid'=>1));
				if($ret){
					echo '充值成功!!';
				}else{
					echo '304充值失败';
				}
			}
		   
			
		}
		
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
